﻿CREATE PROCEDURE [dbo].[yaf_post_last10user](
                @BoardID    INT,
                @UserID     INT,
                @PageUserID INT)
AS
    BEGIN
        SET nocount  ON
        SELECT   TOP 10 a.Posted,
                        Subject = c.Topic,
                        a.Message,
                        a.UserID,
                        a.Flags,
                        UserName = Isnull(a.UserName,b.Name),
                        b.Signature,
                        c.TopicID
        FROM     yaf_Message a
                 JOIN yaf_User b
                   ON b.UserID = a.UserID
                 JOIN yaf_Topic c
                   ON c.TopicID = a.TopicID
                 JOIN yaf_Forum d
                   ON d.ForumID = c.ForumID
                 JOIN yaf_Category e
                   ON e.CategoryID = d.CategoryID
                 JOIN yaf_vaccess x
                   ON x.ForumID = d.ForumID
        WHERE    a.UserID = @UserID
        AND x.UserID = @PageUserID
        AND x.ReadAccess <> 0
        AND e.BoardID = @BoardID
        AND (a.Flags & 24) = 16
        AND (c.Flags & 8) = 0
        ORDER BY a.Posted DESC
    END


